<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>PCCA</title>
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<link rel="stylesheet" type="text/css" href="fonts/fonts.css">
	<script type="text/javascript" src="js/Adaptive.js"></script>
	<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	
	<script type="text/javascript" src="js/weixin.js"></script>



</head>
<body>
	<audio id="myAudio" src="audio/1095.mp3" loop></audio>
	<section id="MaxCon" class="pageThree">
		<div class="timeCon" id="timeCon" style="font-family: 'PORSCHEMOTORSPORTEXTENDED';">0:00.00</div>
		

		<div class="dialPlate">
			<div class="pointer" id="pointer"></div>
			<div class="button" id="button"></div>
		</div>
	</section>

	<!-- <script type="text/javascript" src="js/index.js"></script> -->

	<script type="text/javascript">


		$(function() {
			var Deg = 6; 
			var OneUnit = Deg*10;
			var MaxDeg = 120;
			var MinDeg = -120;
			var initDeg = (OneUnit*2)-MaxDeg;
			var timeout = null;


			var MaxintervalValue = (OneUnit*1.3)-MaxDeg;
			var MinintervalValue = (OneUnit*1.2)-MaxDeg;

			var timeMao = null;

			var minute = 0;
			var second = 0;
			var millisecond = 0;

			var isOneClick = true;



			console.log(MaxintervalValue)
			console.log(MinintervalValue)

			console.log(window);

			function timeoutFun(argument) {
				timeout = setTimeout(function() {
					initDeg = initDeg - (Deg*0.7);

					console.log(initDeg)

					if (initDeg > MinDeg) {
						animateFun(0.5, initDeg)
						timeoutFun();
					}else{
						clearTimeout(timeout);
					}


					
					
				}, 150);
			}




			function animateFun(time, initDeg) {
				if (initDeg > MinDeg) {
					$('#pointer').css({
						transition : 'all '+time+'s',
						transform : 'rotate('+initDeg+'deg)'
					});
				}
				
			}

			animateFun(2, initDeg)




			function jishiFun() {
				timeMao = setTimeout(function() {
					millisecond ++
					if (millisecond == 99) {

						millisecond = 0;
						second ++ ;
						if (second == 59) {
							second = 0;
							minute ++ ;
						}

					}
					if (second == 20) {
						clearTimeout(timeMao);
						console.log('失败！');
						ChangeWindowLocatin('overtime', 'error');
						return ;
					}


					$('#timeCon').text(isLengthOne(minute)+':'+isLengthOne(second)+'.'+isLengthOne(millisecond));
					jishiFun();

				},10)
			}

			

			function isLengthOne(ind) {
				if (ind.toString().length == 1) {
					return '0'+ind;
				}else{
					return ind;
				}
			}


		

			$('#button')[0].addEventListener('touchstart',function(even){
				even.preventDefault(); 
				

				$('#myAudio')[0].play();
				// console.log(even.targetTouches[0].pageX);
				// console.log('touchstart');
				$('#button').addClass('buttonAct');
				initDeg = initDeg - (Deg* Math.random().toFixed(2));
				animateFun(1.0, initDeg)
				timeoutFun();

				if (isOneClick) {
					isOneClick = false;
					jishiFun();
				}
				



			},false);

			$('#button')[0].addEventListener('touchend',function(even){

				$('#myAudio')[0].pause();

				console.log('touchend');
				$('#button').removeClass('buttonAct');
				clearTimeout(timeout);




				console.log(initDeg);

				if (initDeg <=MaxintervalValue && initDeg >=MinintervalValue) {
					console.log('correct 正确');

					if (second <= 6) {
						ChangeWindowLocatin('succeed', 'secss');
						return ;
					}else if (second > 6 && second <= 11) {
						ChangeWindowLocatin('succeedTwo', 'secss');
						return ;
					}else if (second > 11 && second <= 20) {
						ChangeWindowLocatin('succeedThrre', 'secss');
						return ;
					}
					
					return ;
				}if (initDeg < MinintervalValue) {
					console.log('correct 失败');
					clearTimeout(timeMao);
					ChangeWindowLocatin('defeated', 'error')
					return ;

				}
			},false);


			function ChangeWindowLocatin(status, linkFo) {
				setTimeout(function() {
					window.location.href = 'over.html?result='+status+'&time='+isLengthOne(second)+'.'+isLengthOne(millisecond)+'&minute='+minute+'&second='+second+'&millisecond='+millisecond+'&linkFo='+linkFo;
				},700)
			}

		})
	</script>
</body>
</html>